<template xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
  <div>
    <group label-width="22vw">
      <x-input title="主题" placeholder="请输入主题" v-model="sq_title"></x-input>
      <selector title="写信目的" :options="list1" v-model="pur_id"></selector>
      <x-textarea title="信件内容" placeholder="请输入信件内容" :autosize="true" v-model="sq_content"></x-textarea>
      <x-input title="姓名" placeholder="请输入姓名" v-model="sq_realname"></x-input>
      <x-input title="电话" placeholder="请输入电话" v-model="sq_phone" type="number"></x-input>
      <x-input title="地址" placeholder="请输入地址" v-model="sq_address"></x-input>
      <x-input title="电子邮箱" placeholder="请输入电子邮箱" v-model="sq_mail" type="email"></x-input>
      <selector title="反馈方式" :options="list3" v-model="sq_rstype"></selector>
    </group>

    <x-button class="from_submit" type="primary" action-type="button" @click.native="submits">提交</x-button>
    <toast text="Hello World"></toast>
  </div>
</template>

<script>
  import XInput from 'vux/src/components/x-input/index'
  import Group from 'vux/src/components/group/index'
  import XButton from 'vux/src/components/x-button/index'
  import Selector from 'vux/src/components/selector/index'
  import XTextarea from 'vux/src/components/x-textarea/index'
  import Toast from 'vux/src/components/toast/index'

  export default {
    components: {
      XInput,
      XButton,
      Group,
      Selector,
      XTextarea,
      Toast
    },
    data () {
      return {
        sq_title: '',
        pur_id: 1,
        sq_content: '',
        sq_realname: JSON.parse(localStorage.user).realName,
        sq_phone: JSON.parse(localStorage.user).phoneNo,
        sq_address: JSON.parse(localStorage.user).address,
        sq_mail: JSON.parse(localStorage.user).email,
        sq_vocation: '在咸阳app',
        sq_rstype: 1,
        list1: [{key: 1, value: '投诉'}, {key: 2, value: '咨询'}, {key: 3, value: '建议'}, {key: 4, value: '表扬'}],
        list3: [{key: 1, value: '电话反馈'}, {key: 2, value: '在线反馈'}]
      }
    },
    mounted () {
      this.restCode()
    },
    methods: {
      restCode () {
        let codeUrl = 'https://ydt.xy12345.cn/edot/imageServlet?t='
        let codeTime = new Date().getTime()
        this.codeImg = codeUrl + codeTime
      },
      submits () {
        if (this.sq_title === '') {
          this.$vux.toast.text('主题不能为空', 'middle')
          return
        }
        if (this.sq_content === '') {
          this.$vux.toast.text('信件内容不能为空', 'middle')
          return
        }
        let url = 'https://ydt.xy12345.cn/edot/api/app12345Mail/sendMail'
        let param = {
          sq_title: this.sq_title,
          pur_id: this.pur_id,
          sq_content: this.sq_content,
          sq_realname: this.sq_realname,
          sq_phone: this.sq_phone,
          sq_address: this.sq_address,
          sq_mail: this.sq_mail,
          sq_rstype: this.sq_rstype,
          sq_vocation: this.sq_vocation
        }
        this.$axios.post(url, this.$qs.stringify(param)).then(response => {
          let data = response.data
          if (data.code === 0) {
            this.$router.push({path: '/12345/success'})
          } else {
            this.$vux.toast.text(data.message, 'middle')
          }
        })
      }
    }
  }
</script>

<style scoped>
  .from_submit {
    width: 90vw;
    margin: 5vw auto;
  }
</style>
